/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020.
 * Description: process flags
 * Author: yanbo <joey.yanbo@huawei.com>
 * Create: 2020-01-19
 */
#include <linux/types.h>
#include <linux/hal/flag_cmdline.h>

unsigned int __attribute__((section(".data"))) rtos_flag[RTOS_FLAG_ARRAY_LEN];

static unsigned int bit_is_set(const unsigned int *flag, int bit_offset)
{
	int offset = bit_offset / BITS_PER_INT;
	unsigned int mask = (1 << (unsigned int)(bit_offset % BITS_PER_INT));

	return (flag[offset] & mask);
}

static void rtos_set_ibe(void)
{
	unsigned int value;

	/* Enable invalidates of BTB */
	asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (value));
	value = value | 0x1;
	asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (value));
}

void process_rtos_flag(unsigned int *flag)
{
	if (bit_is_set(flag, BIT_SET_IBE) != 0)
		rtos_set_ibe();
}
